package com.mobile.view.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用配置
 *
 * @author lr
 */
@Configuration
public class ResourcesConfig implements WebMvcConfigurer {

    @Value("${web.upload.path}")
    private String uploadPath;


    /**
     * 默认首页的设置，当输入域名是可以自动跳转到默认指定的网页
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // registry.addViewController("/").setViewName("forward:" + indexUrl);
        // 首页地址
        String indexUrl = "/index";
        registry.addRedirectViewController("/", indexUrl);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 文件上传路径 */
        String[] pathFile = uploadPath.split(",");
        for (int i = 0; i < pathFile.length; i++) {
            //  registry.addResourceHandler("/profile/**").addResourceLocations("file:" + RuoYiConfig.getProfilegetProfile());
            registry.addResourceHandler("/files/" + i + "/**").addResourceLocations(
                    "file:" + pathFile[i]);
        }
    }

}